using System;
using System.Text;

namespace PropertyExpression.PresentationCode.CodeGenerator
{
    internal class SimplePropertyOverloadedAndPrefixMethodsBuilder : IOverloadedAndPrefixMethodsBuilder
    {
        private readonly string methodName;
        private readonly Type type;

        public SimplePropertyOverloadedAndPrefixMethodsBuilder(string methodName, Type type)
        {
            this.methodName = methodName;
            this.type = type;
        }

        public void BuildOverloadedMethods(Type parameterType, StringBuilder stringBuilder, string signatureParametersString, string invokeParametersString)
        {
            stringBuilder.AppendFormat(
                @"        public static {2} {0}(this {2} it, {1})
        {{
            return it.{0}(new {3}({4}));
        }}
",
                methodName,
                signatureParametersString,
                type,
                InternalUtil.GetCSharTypeName(parameterType),
                invokeParametersString);
        }

        public void BuildMethodsWithPrefix(StringBuilder methodsBuilder, string prefix, Type holderType)
        {
            methodsBuilder.AppendFormat(
                @"        public static {2} {0}_{1}(this {2} it)
        {{
            return it.{0}({3}.{1});
        }}
",
                methodName, prefix, type, holderType);
        }
    }
}